package com.shk.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.shk.dao.MemberDao;
import com.shk.dao.OrderDao;
import com.shk.service.ReportService;
import com.shk.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private OrderDao orderDao;
    @Autowired
    private MemberDao memberDao;

    @Override
    public List<Map> findNameAndCount() {
        List<Map> list = orderDao.findNameAndCount();
        return list;
    }

    @Override
    public Map getBusinessReportData() throws Exception {
        /*  reportDate:null,
                    todayNewMember :0,  /*新增会员数*//*
        totalMember :0,         *//*总会员数*//*
                thisWeekNewMember :0,  *//*本周新增会员数*//*
                thisMonthNewMember :0,*//*本月新增会员数*//*
                todayOrderNumber :0,    *//*今日预约数*//*
                todayVisitsNumber :0,   *//*今日到诊数*//*
                thisWeekOrderNumber :0, *//*本周预约数*//*
                thisWeekVisitsNumber :0,    *//*本周到诊数*//*
                thisMonthOrderNumber :0,*//*本月预约数*//*
                thisMonthVisitsNumber :0,*//*本月到诊数*/
         /*获取当前日期*/
        Date date = DateUtils.getToday();
        String today = DateUtils.parseDate2String(date);
        /*获取本周一的日期*/
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        /*获取本月第一天的日期*/
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        /*获取当天新增会员数*/
        Integer todayNewMember = memberDao.findCountByToday(today);
        /*获取总的会员数*/
        Integer totalMember = memberDao.findCount();
        /*获取本周新增会员数  查询大于等于周一的数据*/
      Integer thisWeekNewMember = memberDao.findCountByThisWeek(thisWeekMonday);
      /*获取本月新增会员数*/
      Integer thisMonthNewMember = memberDao.findCountByThisMonth(firstDay4ThisMonth);
      /*获取今日预约数*/
       Integer todayOrderNumber = orderDao.findByToday(today);
       /*获取今日到诊数*/
        Integer todayVisitsNumber = orderDao.findOrderStatusCountByToday(today);
        /*获取本周预约数*/
        Integer thisWeekOrderNumber = orderDao.findCountByThisWeek(thisWeekMonday);
        /*获取本周到诊数*/
        Integer thisWeekVisitsNumber = orderDao.findOrderStatusCountByThisWeek(thisWeekMonday);
        /*获取本月预约数*/
        Integer thisMonthOrderNumber = orderDao.findCountByThisMonth(firstDay4ThisMonth);
        /*获取本月到诊数*/
        Integer thisMonthVisitsNumber = orderDao.findOrderStatusCountByThisMonth(firstDay4ThisMonth);
        /*获取热门套餐数据*/
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        Map map = new HashMap();
        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
